from imageDeal import ImageDeal

class Presenter(object):
    def __init__(self, model, view) -> None:
        self.model = model
        self.view = view

        # 实现沟通
        self.model.setPresenter(self)
        self.view.setPresenter(self)

    def onPredictButtonClicked(self, image, callback):
        imagePath = "./image/preImage.png"
        image.save(imagePath)
        # 图像分割
        ID = ImageDeal(imagePath)
        imageSagList = ID.getImageSagList()
        if len(imageSagList) == 0:
            return
        # 图像优化
        tragetImageList = ID.transMNIST(imageSagList)
        # 预测
        labelList = self.model.getLabelList(tragetImageList)

        # 返回
        callback(labelList)
